package com.agri.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OpenApiConfig {
    @Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title("Agri-Fin-Sale API")
                        .version("1.0")
                        .description("农产品融销平台API文档\n\n" +
                                "## 测试账号\n" +
                                "- **管理员**: admin / admin123 (拥有ADMIN和USER角色)\n" +
                                "- **普通用户**: user / user123 (拥有USER角色)\n\n" +
                                "## 使用流程\n" +
                                "1. 首先调用 `/api/public/login` 获取JWT token\n" +
                                "2. 点击右上角 Authorize 按钮，输入: Bearer {你的token}\n" +
                                "3. 然后就可以测试其他需要认证的接口"))
                .addSecurityItem(new SecurityRequirement().addList("JWT"))
                .components(new Components()
                        .addSecuritySchemes("JWT", new SecurityScheme()
                                .name("JWT")
                                .type(SecurityScheme.Type.HTTP)
                                .scheme("bearer")
                                .bearerFormat("JWT")
                                .description("请输入JWT token，格式: Bearer {token}")));
    }
}